﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using WarehouseWebAPP.code.BLL;

namespace WarehouseWebAPP.Pages.admin.Edit_Entities
{
    public partial class EditUserTypes : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            ErrorLabel.Visible = false;
        }

        protected void CustomValidator1_ServerValidate(object source, ServerValidateEventArgs args)
        {
            UserTypeBLL BLL = new UserTypeBLL();
            String Previous = BLL.UserTypeGetByNum((Guid)UserTypeDetailsView.SelectedValue)[0].user_type;


            if (Previous != args.Value)
            {
                try
                {
                    if (BLL.UserTypeGetByName(args.Value).Rows.Count > 0)
                        args.IsValid = false;
                    else
                        args.IsValid = true;
                }
                finally
                {
                    //TODO: Dispose
                }

            }
        }

        protected void UserTypeDetailsView_ItemDeleting(object sender, DetailsViewDeleteEventArgs e)
        {
            try
            {
                Label Label = (Label)UserTypeDetailsView.FindControl("UserTypeLabel");
                UserTypeBLL BLL = new UserTypeBLL();
                Guid guid = BLL.UserTypeGetByName(Label.Text)[0].user_type_num;

                UserBLL CBLL = new UserBLL();
                if (CBLL.userGetByType(guid).Rows.Count > 0)
                {
                    ErrorLabel.Visible = true;
                    e.Cancel = true;

                }

            }
            finally
            {
                //TODO: Dispose
            }
        }
    }
}
